//
//  MorePopUI.m
//  mbstore
//
//  Created by Juvid on 14-4-17.
//  Copyright (c) 2014年 huangyi. All rights reserved.
//

#import "MorePopUI.h"
#import "UIColor+expanded.h"
#import "StockUIV.h"
static UIPopoverController *popoverUI=nil;
@interface MorePopUI ()

@end

@implementation MorePopUI

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.bounces=NO;
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier=@"pdt";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.clipsToBounds=YES;
    }
    else{
        while ([cell.contentView.subviews lastObject] != nil)
        {
            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
        
    }
    UIImageView *imgLine=[[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight([self.tableView rectForRowAtIndexPath:indexPath])-1, CGRectGetWidth([self.tableView rectForRowAtIndexPath:indexPath]), 1)];
    imgLine.image=[UIImage imageNamed:@"tableLine"];
    [cell.contentView addSubview:imgLine];
    
    NSArray *arr=[NSArray arrayWithObjects:@"库存查询",@"店铺促销",@"发放二维码",@"stock",@"activity",@"card", nil];
    UIView *vieBack=[[UIView alloc]initWithFrame:cell.frame];
    vieBack.backgroundColor=[UIColor colorWithHexString:@"0x525151"];
    cell.selectedBackgroundView=vieBack;
    
    cell.imageView.image=[UIImage imageNamed:[arr objectAtIndex:indexPath.row+3]];
    cell.textLabel.text=[arr objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont boldSystemFontOfSize:16];
    cell.textLabel.textColor=[UIColor whiteColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
   
    if (popoverUI.isPopoverVisible) {
        [popoverUI dismissPopoverAnimated:YES];
        HomeUI *home=self.delegate;
        [home setSelect:indexPath.row];
    }
   
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(void)showFromView:(UIView*)view{
    UIPopoverController *pop=[[UIPopoverController alloc] initWithContentViewController:self];
    [pop presentPopoverFromRect:view.frame inView:view.superview permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    pop.backgroundColor=[UIColor colorWithHexString:@"0x666666"];
    pop.delegate=self;
    popoverUI=pop;
}
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{
    popoverUI=nil;
}
-(void)setItems:(NSArray*)items{
    CGSize sz=CGSizeMake(170, CGRectGetHeight([self.tableView rectForRowAtIndexPath:0])*3-1);
    //    self.contentSizeForViewInPopover=sz;
    self.preferredContentSize=sz;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
